package net.cyndeline.entitySystem

/**
 * Manages events by sending them to the event handlers that have
 * registered themselves to events of that type.
 */
trait EventSystem {
  
  /**
   * Process all pending events.
   */
  def process: Unit

  /**
   * Lets an EventHandlerSystem register itself as interested in a set of
   * events. What those events are will be determined using the handler itself.
   * Default priority for receiving events will be given to this handler.
   * @param handler Event handler to register.
   */
  def registerEventHandler[T <: Event](handler: EventHandlerSystem): Unit
  
  /**
   * Registers an event handler as well as specifying what priority the
   * handler should have. Use the predefined priority values.
   * @see EventPriority
   */
  def registerEventHandler[T <: Event](handler: EventHandlerSystem, priority: Int): Unit
  
  /**
   * Sends an event to all handlers interested in the entity's components.
   * @param entity The entity that received the event.
   * @param event The event itself.
   */
  def deliverEvent(entity: EntityRef, event: Event): Unit

  /**
   * Remove all handlers.
   */
  def clear: Unit
  
  /**
   * Modifies the system by adding event-handling systems to it.
   */
  def setup(setting: EventSystemSetup): Unit
}